package pixivhelper.bravedefault.com;

import com.google.gson.*;

import java.lang.reflect.Type;

public class Oauth {
    public String access_token;
    public String device_token;
    public String expires_in;
    public String token_type;
    public String scope;
    public String refresh_token;
    public String authorizeTime;
    public User user;

    @Override
    public String toString() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }

    public static class OauthAdapter implements JsonDeserializer<Oauth> {

        @Override
        public Oauth deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
            JsonObject response = json.getAsJsonObject();
            JsonObject oauth = response.get("response").getAsJsonObject();
            Gson gson = new Gson();
            return gson.fromJson(oauth, Oauth.class);
        }
    }
}
